package com.njupt.simulation.controller;

import com.njupt.simulation.entity.*;
import com.njupt.simulation.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/caculate")
public class CaculateController {

    @Autowired
    private LeoSatelliteService leoSatelliteService;

    @Autowired
    private GeoSatelliteService geoSatelliteService;

    @Autowired
    private StationService stationService;
    @Autowired
    private ConstellationService constellationService;
    @Autowired
    private IMTService imtService;
    @Autowired
    private MobileTerminalService mobileTerminalService;
    @Autowired
    private IMTBaseService imtBaseService;

    @GetMapping("/{linktypeid}/{linktype}/{direction}/{nodetype}/{nodeid}/carrier/{id}")
    public ResponseEntity<?> findObject(@PathVariable String linktype, @PathVariable String direction, @PathVariable String nodetype, @PathVariable Integer nodeid) {
        // 根据linktype判断是受扰还是干扰



        if ("disturbed".equals(linktype)) {
            // 如果是受扰，执行受扰逻辑


            //找到发射端对象及参数
            if("transmit".equals(direction)){
                //如果是发射端，判断发射端类型
                if("leosatellite".equals(nodetype)){
                    //如果是低轨卫星，根据id号找到数据库中对应的数据
                    LeoSatellite leoSatellite = leoSatelliteService.findById(nodeid);

                } else if ("geosatellite".equals(nodetype)){
                    GeoSatellite geoSatellite = geoSatelliteService.findById(nodeid);
                } else if ("station".equals(nodetype)){
                    Station station = stationService.findById(nodeid);
                } else if ("constellation".equals(nodetype)){
                    Constellation constellation = constellationService.findById(nodeid);
                }else if ("IMTterminal".equals(nodetype)){
                    IMTTerminal imtTerminal = imtService.findById(nodeid);
                }else if("Mobileterminal".equals(nodetype)){
                    MobileTerminal mobileTerminal = mobileTerminalService.findById(nodeid);
                }else {
                    IMTBase imt_base = imtBaseService.findById(nodeid);
                }
            }//找到接受端对象及参数
            else if("receive".equals(direction)){
                //如果是接收端，判断接收端类型
                if("leosatellite".equals(nodetype)){
                    //如果是低轨卫星，根据id号找到数据库中对应的数据
                    LeoSatellite leoSatellite = leoSatelliteService.findById(nodeid);
                } else if ("geosatellite".equals(nodetype)){
                    GeoSatellite geoSatellite = geoSatelliteService.findById(nodeid);
                } else if ("station".equals(nodetype)){
                    Station station = stationService.findById(nodeid);
                } else if ("constellation".equals(nodetype)){
                    Constellation constellation = constellationService.findById(nodeid);
                }else if ("IMTterminal".equals(nodetype)){
                    IMTTerminal IMTterminal = imtService.findById(nodeid);
                }else if("Mobileterminal".equals(nodetype)){
                    MobileTerminal mobileTerminal = mobileTerminalService.findById(nodeid);
                }else {
                    IMTBase imt_base = imtBaseService.findById(nodeid);
                }
            }
        } else if ("interference".equals(linktype)) {
            // 如果是干扰，执行干扰逻辑

        } else {
            // 如果不是受扰或干扰，返回错误信息
            return ResponseEntity.badRequest().body("Invalid linktype. Please specify 'disturbed' or 'interference'.");
        }

        return null;
    }

}
